import { checkUsername, checkPassword } from './utils.js'

import axios from 'axios'

import './css/index.css'
import './css/index.less'

import imgObj from '@/assets/logo.png'

document.querySelector('.logo-img').src = imgObj
document.querySelector('.login-btn').addEventListener('click', async () => {
  const username = document.querySelector('.username').value
  const password = document.querySelector('.password').value
  if (!checkUsername(username)) {
    return alert('输入正确的账户')
  }
  if (!checkPassword(password)) {
    return alert('输入正确的密码')
  }
  try{
    // console.log('准备注册')
    const res = await axios({
      url: 'http://hmajax.itheima.net/api/register',
      method: 'post',
      data: {
        username,
        password
      }
    })
    alert(res.data.message)
  } catch (e) {
    alert(e.response.data.message)
  }
})

const arr = [1, 2, 3, 4, 5]
const newArr = arr.map(item => item + 1)
console.log(newArr)